package config

import (
	"github.com/spf13/viper"
	"log"
)

type AppConfig struct {
	Mysql struct {
		Host     string
		Port     string
		Username string
		Password string
		Database string
	}
	Redis struct {
		Addr     string
		Password string
		Database int
	}
	QiNiuYun struct {
		AccessKey string
		SecretKey string
		Url       string
		Bucket    string
	}
}

var ConfigData AppConfig

func Init() {
	viper.SetConfigFile("../config/config.yaml")

	if err := viper.ReadInConfig(); err != nil {
		panic("配置文件读取失败")
	} else {
		log.Println("配置文件读取成功")
	}

	err := viper.Unmarshal(&ConfigData)
	if err != nil {
		panic("配置文件解析失败")
	} else {
		log.Println("配置文件解析成功", ConfigData)
	}
}
